
require 'mysql'


def exec(db, sql_file)
	if File.exists? sql_file
		l = File.readlines(sql_file).collect{|line| line if not line.start_with?('#') and not line.start_with?('/*')}
		sql_content = l.join()
		sqls = sql_content.split(';')
		for sql in sqls
			sql = sql.strip
			db.query(sql) if sql.size > 0
		end
		true
	end
	false
end


begin
	# connect to the server
	db = Mysql.real_connect("127.0.0.1", "root", "", "nuclide")
	# get server version string and display it
	exec(db, '../Scada.Center.Web/schema/nuclide.sql')
rescue MysqlError => e
	puts "Error code: #{e.errno}"
	puts "Error message: #{e.error}"
ensure
	# disconnect from server
	db.close if db
end